package org.jeecg.modules.api.member.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.api.member.entity.Member;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Description: 用户分销信息
 * @Author: jeecg-boot
 * @Date:   2024-09-19
 * @Version: V1.0
 */
public interface MemberMapper extends BaseMapper<Member> {
    @Update("update fx_member set withdraw_money=withdraw_money-#{amount} where id=#{id} and withdraw_money>#{amount} and #{amount}>0")
    int subWithdrawMoney(@Param("id")Long id, @Param("amount")BigDecimal amount);

    @Update("update fx_member set withdraw_money=withdraw_money+#{amount} where id=#{id} and  #{amount}>0")
    int addWithdrawMoney(@Param("id")Long id, @Param("amount")BigDecimal amount);

    @Select("select count(1) from fx_member ")
    int count();

    @Select("select count(1) from fx_member where recommend_id is not null and recommend_id!=0  and DATE_FORMAT(create_time,'%Y-%m')=#{time}")
    int sumRecCount(@Param("time")String time);

    @Select("select ifnull(sum(commission),0) as commission,ifnull(sum(withdraw_money),0) as withdrawMoney from fx_member;")
    Map<String,BigDecimal> getCommissionAmount();

}
